package com.lh.music.test;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RelativeLayout;
import android.widget.VideoView;

import com.lh.music.R;

public class VideoActivity extends AppCompatActivity {
    private static final String videoUrl="http://192.168.191.1:8080/SchoolLife/vedio/demo.mp4";
    private static  String videoLocation="";
    private VideoView video;
    private int videoHeight;
    private int videoWidth;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        video= (VideoView) findViewById(R.id.video);
        videoLocation="android/resource://"+getPackageName()+"/"+R.raw.test;
    //    playBySystem();
        initVideoView();
    }
    //
    private void initVideoView(){
        video.setVideoPath(videoUrl);
        initVideoSize(0);
        video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                video.start();
            }
        });
    }
    private void playBySystem(){
        Uri uri=Uri.parse(videoUrl);
        Intent intent=new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri,"video/*");
        startActivity(intent);
    }
    private void initVideoSize(int mode){
        if (mode==0){
            //设置视频充满整个屏幕
            RelativeLayout.LayoutParams lp= (RelativeLayout.LayoutParams) video.getLayoutParams();
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            video.setLayoutParams(lp);
        }else{

        }
    }
}
